//
//  DoctorApplyController.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/18.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "DoctorApplyController.h"
#import "DoctorApplyTableViewCell.h"
#import "DoctorApplyModel.h"
#import "AppointmentDoctorViewController.h"

@interface DoctorApplyController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *cellArr;
@end
static NSString *cellID = @"cellid";
@implementation DoctorApplyController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    [self setupUI];
}

#pragma mark
#pragma mark - 获取数据
-(void)getData{

    //json转数组
    NSString *path = [[NSBundle mainBundle] pathForResource:@"patientMessage.json" ofType:nil];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error: nil];
    
    NSMutableArray *mArr = [NSMutableArray array];
    for (NSDictionary *dict in arr) {
        DoctorApplyModel *model = [DoctorApplyModel doctorApplyWithDict:dict];
        [mArr addObject:model];
    }
    
    self.cellArr = mArr.copy;
}

-(void)setupUI{
    
    //创建tableView
    UITableView *tabV = [[UITableView alloc] init];
    
    //添加tabView
    [self.view addSubview:tabV];
    
    //设置代理和数据源方法
    tabV.dataSource = self;
    tabV.delegate = self;
    
    tabV.rowHeight = 120;
    
    //注册cell
//    [tabV registerClass:[DoctorApplyTableViewCell class] forCellReuseIdentifier:cellID];
    [tabV registerNib:[UINib nibWithNibName:@"DoctorApplyTableViewCell" bundle:nil] forCellReuseIdentifier:cellID];
    //自动布局
    [tabV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        //与屏幕大小相同
        make.edges.mas_equalTo(self.view);
        
    }];
    
}

#pragma mark
#pragma mark - 设置tableView数据源方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cellArr.count;
}

//cell单元格
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //重用cell
    DoctorApplyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    //cell赋值
    cell.model = self.cellArr[indexPath.row];
    
    return cell;
    
}

#pragma mark
#pragma mark - 点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AppointmentDoctorViewController *appointmentVC = [[AppointmentDoctorViewController alloc]init];
    
    [self jumpToNextViewController:appointmentVC];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
